﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using TrabalhoLAP.Model.Class;
using TrabalhoLAP.Model.DAO;

namespace TrabalhoLAP.Controller
{
    public class MaintainProfessor
    {
        public ArrayList consultarProfessor(string nomeProfessor, string codProfessor, string loginProfessor, string statusRegistro)
        {
            ProfessorDAO dao = new ProfessorDAO();
            DataSet ds = new DataSet();

            ArrayList Professors = new ArrayList();

            ds = dao.consultarProfessor(nomeProfessor, codProfessor, loginProfessor, statusRegistro);

            if (ds == null || ds.Tables.Count == 0)
                return Professors;

            foreach( DataRow linha in ds.Tables[0].Rows)
            {
                Professor Professor = new Professor();

                Professor.CodProfessor = linha[0].ToString();
                Professor.NomeProfessor = linha[1].ToString();
                Professor.LoginProfessor = linha[2].ToString();
                Professor.SenhaProfessor = linha[3].ToString();
                Professor.StatusRegistro = linha[5].ToString().Equals("1") ? true : false;

                Professors.Add(Professor);
            }

            return Professors;
        }

        public bool atualizarProfessor(string codProfessor, string nomeProfessor, string loginProfessor, string senhaProfessor, string statusRegistro)
        {
            ProfessorDAO dao = new ProfessorDAO();
            return dao.alterarProfessor(codProfessor, nomeProfessor, loginProfessor, senhaProfessor, statusRegistro);
        }

        public bool cadastrarProfessor(string nomeProfessor, string loginProfessor, string senhaProfessor, string statusRegistro)
        {
            ProfessorDAO dao = new ProfessorDAO();
            return dao.cadastrarProfessor(nomeProfessor, loginProfessor, senhaProfessor, statusRegistro);
        }
    }
}